﻿using Sunxsh.Es.Common;
using Microsoft.EntityFrameworkCore;

namespace Sunxsh.Es.Core.Db;

public abstract class MainDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (AppConfig.Settings.DbType == "SqlServer")
        {
            optionsBuilder.UseSqlServer(AppConfig.Settings.SqlserverConnection);
        }
        else if (AppConfig.Settings.DbType == "MySql")
        {
            optionsBuilder.UseMySql(AppConfig.Settings.MySqlConnection, ServerVersion.AutoDetect(AppConfig.Settings.MySqlConnection));
        }
        else
        {
            throw new Exception($"数据库类型 【{AppConfig.Settings.DbType}】 不支持。");
        }
    }

}
